﻿using System;
using System.Xml;
using System.Configuration;
namespace Maticsoft.DBUtility
{
    
    public class PubConstant
    {        
        /// <summary>
        /// 获取连接字符串
        /// </summary>
        public static string ConnectionString
        {           
            get 
            {
                string _connectionString = "";
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load("bookstore.xml");
                XmlNodeList nls = xmlDoc.SelectSingleNode("/bookstore/book").ChildNodes;//获取bookstore节点的所有子节点             
                foreach(XmlNode xn1 in nls)//遍历        
                {
                    XmlElement xe2 = (XmlElement)xn1;//将子节点类型转换为XmlElement类型 
                    if (xn1.Name == "author")//如果找到                  
                      {
                          _connectionString = xe2.InnerText;
                          _connectionString = Maticsoft.DBUtility.DESEncrypt.Decrypt(_connectionString);
                          break;//找到退出来就可以了        
                      }
                 }     
        
                return _connectionString; 
            }
        }
        public static void writexml(string wstring)//写入
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("bookstore.xml");
            XmlNodeList nls = xmlDoc.SelectSingleNode("/bookstore/book").ChildNodes;//获取bookstore节点的所有子节点             
            foreach (XmlNode xn1 in nls)//遍历        
            {
                XmlElement xe2 = (XmlElement)xn1;//将子节点类型转换为XmlElement类型 
                if (xn1.Name == "author")//如果找到                  
                {
                   xe2.InnerText = wstring;                  
                    break;//找到退出来就可以了        
                }
            }
            xmlDoc.Save("bookstore.xml");
        }

    }
}
